//
//  GSPublicMethod.h
//  GSDemo
//
//  Created by ZFJMAC on 2022/7/23.
//

#ifndef GSPublicMethod_h
#define GSPublicMethod_h

/// 默认图片
static inline UIImage *kPlaceholderImg(){
    return [UIImage imageNamed:@"mb_placeholder_img"];
}

static inline CGFloat kMarginSize_20(){
    return 20;
}

static inline CGFloat kMarginSize(){
    return 15;
}

static inline CGFloat kMarginSize_10(){
    return 10;
}

static inline CGFloat kMarginSize_8(){
    return 8;
}

/// 判断是不是空
static inline BOOL kEmptyString(NSString *str){
    if (!str) {
        return YES;
    }
    if (![str isKindOfClass:[NSString class]]) {
        return YES;
    }
    if (str.length == 0) {
        return YES;
    }
    return NO;
}

/// 强制转换字符串
static inline NSString *kStringValue(id str){
    if (!str || [str isKindOfClass:[NSNull class]]) {
        return @"";
    }
    if (![str isKindOfClass:[NSString class]]) {
        return [NSString stringWithFormat:@"%@", str];
    }
    return str;
}

/// 获取随机颜色
static inline UIColor *kRandomColor(){
    NSInteger aRedValue = arc4random() % 255;
    NSInteger aGreenValue = arc4random() % 255;
    NSInteger aBlueValue = arc4random() % 255;
    UIColor *randColor = [UIColor colorWithRed:aRedValue /255.0f green:aGreenValue /255.0f blue:aBlueValue /255.0f alpha:1.0];
    return randColor;
}

static inline UIColor *kRandomColorAlpha(CGFloat alpha){
    NSInteger aRedValue = arc4random() % 255;
    NSInteger aGreenValue = arc4random() % 255;
    NSInteger aBlueValue = arc4random() % 255;
    UIColor *randColor = [UIColor colorWithRed:aRedValue /255.0f green:aGreenValue /255.0f blue:aBlueValue /255.0f alpha:alpha];
    return randColor;
}

/// 屏幕宽高
static inline CGFloat kScreenWidth(){
    return [UIScreen mainScreen].bounds.size.width;
}

static inline CGFloat kScreenHeight(){
    return [UIScreen mainScreen].bounds.size.height;
}

/// 判断是否是刘海手机
static inline BOOL kIsPhoneX(){
    BOOL isPhoneX = NO;
    if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {
        //判断是否是手机
        return isPhoneX;
    }
    if (@available(iOS 11.0, *)) {
        UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
        if (mainWindow.safeAreaInsets.bottom > 0.0) {
            isPhoneX = YES;
        }
    }
    return isPhoneX;
}

/// NavBar高度
static inline CGFloat kNavBarHei(){
    return kIsPhoneX() ? 88 : 64;
}

/// TabBar高度
static inline CGFloat kTabBarHei(){
    return kIsPhoneX() ? 83 : 49;
}

static inline CGFloat kStatusBarHeight(){
    return kIsPhoneX() ? 44 : 20;
}

static inline CGFloat kSafeTopOffset(){
    return kIsPhoneX() ? 44 : 20;
}

static inline CGFloat kSafeBottomOffset(){
    return kIsPhoneX() ? 34 : 0;
}

//缩略图缩放比
static inline CGFloat kScalingRatio(){
    return 2.0;
}

static inline NSUserDefaults *kUserDefaults(){
    return [NSUserDefaults standardUserDefaults];
}

/// 获取时间戳
static inline NSString *kTimeStamp(){
    NSTimeInterval timeInterval = [[NSDate dateWithTimeIntervalSinceNow:0] timeIntervalSince1970];
    NSString *timeStamp = [NSString stringWithFormat:@"%.0f", timeInterval];
    return timeStamp;
}

///
static inline NSString *kTimeFormatter(NSInteger timeStamp){
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:timeStamp];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    NSString *strDate = [formatter stringFromDate:confromTimesp];
    return strDate;
}

#endif /* GSPublicMethod_h */
